export const formatTime = (date: Date) => {
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const hour = date.getHours();
    const minute = date.getMinutes();
    const second = date.getSeconds();

    return (
        [year, month, day].map(formatNumber).join("/") +
        " " +
        [hour, minute, second].map(formatNumber).join(":")
    );
};

const formatNumber = (n: number) => {
    const s = n.toString();
    return s[1] ? s : "0" + s;
};
import dayjs from "dayjs";
// const dayjs = require('dayjs')
export const formatMessageDate = (timestamp: number) => {
    const unix = dayjs().unix();
    const today = dayjs().format("YYYY/MM/DD");
    const yesterday = dayjs((unix - 3600 * 24) * 1000).format("YYYY/MM/DD");
    const createDate = dayjs(timestamp * 1000).format("YYYY/MM/DD");
    const thisYear = today.split("/")[0] === createDate.split("/")[0];
    const yearMonth = dayjs(timestamp * 1000).format("MM/DD");
    const isToday = today === createDate;
    const isYesterday = yesterday === createDate;
    const createTime = dayjs(timestamp * 1000).format("H:mm A");
    return {
        date: isToday
            ? "Today"
            : isYesterday
            ? "Yesterday"
            : thisYear
            ? yearMonth
            : createDate,
        createDate,
        createTime,
    };
};

export const formatAgreeDate = (timestamp: string) => {
    const dateShow = dayjs(timestamp).format("DD/MM/YYYY");
    return dateShow;
};
